package medium;

import java.util.Arrays;

public class T9 {
    public static void main(String[] args) {
        T9 t9 = new T9();
        System.out.println(t9.longestConsecutive(new int[]{100,4,200,1,3,2}));
    }

    public int longestConsecutive(int[] nums) {
        Arrays.sort(nums);
        int max = 0, c = 0;
        if (nums.length == 0){
            return 0;
        }
        for (int i = 0; i < nums.length; i++) {
            if (i > 0 && nums[i] == nums[i - 1] + 1) {
                c++;
            } else if (i > 0 && nums[i] == nums[i - 1]) {
                c = c;
            } else if (i > 0 && nums[i] - nums[i - 1] > 1) {
                max = Math.max(max, c);
                c = 0;
            } if (i==nums.length-1){
                max = Math.max(max, c);
            }
        }
        return max+1;
    }
}
